package cn.yx.user.remote.service.impl;

import cn.yx.user.dos.UserAccountDo;
import cn.yx.user.mapper.UserAccountMapper;
import cn.yx.user.remote.dto.UserAccountRemoteDto;
import cn.yx.user.remote.mapping.UserAccountRemoteMapping;
import cn.yx.user.remote.service.UserAccountRemoteService;
import cn.yx.user.service.UserAccountService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Method;

import java.util.Objects;

/**
 * <p>用户账户远程服务接口实现类</p>
 *
 * @author Wgssmart
 */
@DubboService(methods = {
        @Method(name = "getById")
})
@Slf4j
public class UserAccountRemoteServiceImpl implements UserAccountRemoteService {


    private final UserAccountService userAccountService;

    private final UserAccountMapper userAccountMapper;

    public UserAccountRemoteServiceImpl(UserAccountService userAccountService, UserAccountMapper userAccountMapper) {
        this.userAccountService = userAccountService;
        this.userAccountMapper = userAccountMapper;
    }

    @Override
    public UserAccountRemoteDto getOne(Long id) {
        log.info("remote getOne, id: {}", id);
        return UserAccountRemoteMapping.INSTANCE.dtoToOther(userAccountService.getOne(id));
    }

    @Override
    public UserAccountRemoteDto getByUserName(String userName) {
        log.info("remote getByUserName, username: {}", userName);
        UserAccountDo userAccountDo = userAccountMapper.selectByUserName(userName);
        return Objects.isNull(userAccountDo) ? null : UserAccountRemoteMapping.INSTANCE.doToDto(userAccountDo);
    }
}
